import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { INestApplication } from '@nestjs/common';

export function setupSwagger(app: INestApplication) {
  const config = new DocumentBuilder()
    .setTitle('Yuheng Admin API')
    .setDescription('Yuheng Admin 管理系统 API 接口文档')
    .setVersion('1.0.0')
    .addTag('认证', '用户登录认证相关接口')
    .addTag('用户管理', '用户增删改查相关接口')
    .addTag('菜单管理', '菜单增删改查相关接口')
    .addTag('系统', '系统健康检查等接口')
    .addBearerAuth(
      {
        type: 'http',
        scheme: 'bearer',
        bearerFormat: 'JWT',
        name: 'JWT',
        description: '输入JWT token',
        in: 'header',
      },
      'JWT-auth',
    )
    .build();

  const document = SwaggerModule.createDocument(app, config);

  SwaggerModule.setup('api-docs', app, document, {
    swaggerOptions: {
      persistAuthorization: true,
      tagsSorter: 'alpha',
      operationsSorter: 'alpha',
    },
    customSiteTitle: 'Yuheng Admin API 文档',
    customCss: `
      .swagger-ui .topbar { display: none }
      .swagger-ui .info .title { color: #333; font-size: 36px; }
      .swagger-ui .info .description { font-size: 16px; }
    `,
  });
}
